<template>
  <!--统计-不合格品审理单-->
  <el-container>
    <basic-crud :option="option" apiGetListUrl="/mes/nonconformingController/grid" v-model="formData">
      <template #fileNames="{ row }">
        <el-button type="text" v-for="file in row.fileList" :key="file.id"  @click="downloadFileHandler(file)">{{
            `${file.showName}.${file.fileExtension};`
          }}</el-button>
      </template>
      <template #fileNames-form>
        <el-button type="text" v-for="file in formData.fileList" :key="file.id"  @click="downloadFileHandler(file)">{{
            `${file.showName}.${file.fileExtension};`
          }}</el-button>
      </template>
    </basic-crud>
  </el-container>
</template>

<script setup>
import {formatDate} from "../../../utils/formatTime"
import {downloadFile} from "@/utils/file.js";
import {ref} from "vue";
const formData=ref({})

const option = ref({
  highlightCurrentRow: true,
  addBtn:false,
  editBtn:false,
  viewBtn:true,
  delBtn:false,
  menuWidth:80,
  searchLabelWidth: 120,
  labelWidth: 140,
  column:[
    {
      label: "状态",
      prop: "status",
      search: true,
      display:false,
      sortable: true,
      searchType: "select",
      virtualize: true,
      statusShow: true,
      statusTag:true,
      statusTypeMap:{
        Created:'danger',
        Released:'success',
        Auditing:'warning'
      }
    },
    {
      label: "编号",
      prop: "code",
      display:false,
      minWidth: 200,
      disabled: true,
      search: true
    },
    {
      label: "型号",
      prop: "modelName",
      display:false,
      search: true,
      minWidth: 180,
      disabled: true
    },
    {
      label: "产品名称",
      prop: "productName",
      display:false,
      disabled: true,
      search: true,
      minWidth: 180,
    },
    {
      label: "产品编号",
      prop: "productCode",
      display:false,
      minWidth: 150,
      search: true,
      disabled: true
    },
    {
      label: "生产部门",
      prop: "productDeptName",
      display:false,
      minWidth: 150
    },
    {
      label: "不合格生产处特性",
      prop: "peculiarity",
      display:false,
      width: 120,
      type: "radio",
      virtualize: true,
      dicData: [
        {
          label: "关键特性",
          value: "0",
        },
        {
          label: "重要特性",
          value: "1",
        },
        {
          label: "一般特性",
          value: "2",
        },
      ],
      formatter: (row) => {
        let text = "";
        switch (row.peculiarity) {
          case "0":
            text = "关键特性";
            break;
          case "1":
            text = "重要特性";
            break;
          case "2":
            text = "一般特性";
            break;
        }
        return text;
      },
      span: 24,
    },
    {
      label: "交检数量",
      prop: "inspectionQuantity",
      display:false,
      width: 80,
      type: "number",
    },
    {
      label: "不合格数量",
      prop: "unqualifiedQuantity",
      display:false,
      width: 80,
      type: "number",
    },
    {
      label: "发现时机",
      prop: "findMoment",
      display:false,
      width: 110,
      type: "radio",
      virtualize: true,
      dicData: [
        {
          label: "入所复检",
          value: "0",
        },
        {
          label: "工序交检",
          value: "1",
        },
        {
          label: "出所交检",
          value: "2",
        },
        {
          label: "用户代表检查",
          value: "3",
        },
        {
          label: "生产自查",
          value: "4",
        },
        {
          label: "其他",
          value: "5",
        },
      ],
      formatter: (row) => {
        let text = "";
        switch (row.findMoment) {
          case "0":
            text = "入所复检";
            break;
          case "1":
            text = "工序交检";
            break;
          case "2":
            text = "出所交检";
            break;
          case "3":
            text = "用户代表检查";
            break;
          case "4":
            text = "生产自查";
            break;
          case "5":
            text = "其他";
            break;
        }
        return text;
      },
      span: 24,
    },
    {
      label: "图纸、技术条件要求",
      prop: "technicalRequirements",
      width: 200,
      display:false,
      type: "textarea",
      span: 24,
    },
    {
      label: "检验结论（超差描述）",
      prop: "nonconforming",
      display:false,
      width: 150,
      type: "textarea",
      span: 24,
    },
    {
      label: "提出人",
      prop: "proposerName",
      width: 100,
      display:false,
    },
    {
      label: "提出时间",
      prop: "proposeTime",
      display:false,
      width: 120,
      formatter: (row) => {
        return row.proposeTime?.substring(0, 10) || "";
      },
    },
    {
      label: "归零时间",
      prop: "zeroingTime",
      display:false,
      width: 120,
      formatter: (row) => {
        return row.zeroingTime?.substring(0, 10) || "";
      },
    },  {
      label: "附件",
      prop: "fileNames",
      minWidth: 300,
      editDisplay:false,
      addDisplay:false,
      formslot:true,
      viewDisplay:false,
      span:24
    },
  ],
  group:[
    {
      label: "基本信息",
      prop: "jbinfo",
      labelWidth:110,
      column: [
        {
          label: "编号",
          prop: "code",
          gutter: 32,
          placeholder: "请从质量那边拿到这个编号并填写",
          span: 12,
          value: "",
        },
        {
          label: "单据状态",
          prop: "status",
          gutter: 32,
          type: "select",
          dicData: [
            {
              label: "未处理",
              value: "Created",
            },
            {
              label: "已处理",
              value: "Released",
            },
          ],
          value: "Created",
        },
        {
          label: "型号",
          prop: "modelName",
          disabled: true,
          gutter: 32,
          span: 12,
          value: "",
        },
        {
          label: "产品名称",
          prop: "productName",
          gutter: 32,
          disabled: true,
          span: 12,
          value: "",
        },
        {
          label: "产品编号",
          prop: "productCode",
          disabled: true,
          gutter: 32,
          span: 12,
          value: "",
        },
        {
          label: "交检数量",
          prop: "inspectionQuantity",
          gutter: 32,
          type: "number",
          step: 1,
          min: 1,
          rules: [{ required: true, message: "交检数量不能为空" }],
          span: 12,
          value: 0,
        },
        {
          label: "不合格数量",
          prop: "unqualifiedQuantity",
          gutter: 32,
          type: "number",
          step: 1,
          min: 1,
          rules: [{ required: true, message: "不合格数量不能为空" }],
          span: 12,
          value: 0,
        },
        {
          label: "生产部门",
          prop: "productDeptName",
          gutter: 32,
          type: "select",
          dicData: [
            {
              label: "综合室",
              value: "综合室",
            },
            {
              label: "产品技术室",
              value: "产品技术室",
            },
            {
              label: "制造工程研究室",
              value: "制造工程研究室",
            },
            {
              label: "售后室",
              value: "售后室",
            },
          ],
          rules: [{ required: true, message: "请选择生产部门" }],
          span: 12,
        },
        {
          label: "生产处特性",
          prop: "peculiarity",
          gutter: 32,
          type: "radio",
          dicData: [
            {
              label: "关键特性",
              value: "0",
            },
            {
              label: "重要特性",
              value: "1",
            },
            {
              label: "一般特性",
              value: "2",
            },
          ],
          span: 24,
          value: "0",
        },
        {
          label: "发现时机",
          prop: "findMoment",
          gutter: 32,
          type: "radio",
          dicData: [
            {
              label: "入所复检",
              value: "0",
            },
            {
              label: "工序交检",
              value: "1",
            },
            {
              label: "出所交检",
              value: "2",
            },
            {
              label: "用户代表检查",
              value: "3",
            },
            {
              label: "生产自查",
              value: "4",
            },
            {
              label: "其他",
              value: "5",
            },
          ],
          span: 24,
          value: "0",
        },
        {
          label: "创建时间",
          prop: "proposeTime",
          type: "datetime",
          value: formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"),
          gutter: 32,
          formatter: (row) => {
            return formatDate(row.proposeTime, "yyyy-MM-dd HH:mm:ss");
          },
        },
        {
          label: "完成时间",
          prop: "zeroingTime",
          type: "datetime",
          value: formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"),
          gutter: 32,
          formatter: (row) => {
            return formatDate(row.zeroingTime, "yyyy-MM-dd HH:mm:ss");
          },
        },
      ],
    },
    {
      label: "不合格内容",
      prop: "jbinfos",
      column: [
        {
          label: "图纸，技术条件要求",
          prop: "technicalRequirements",
          type: "textarea",
          labelPosition: "top",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
          value: "",
        },
        {
          label: "处理措施",
          prop: "solution",
          type: "textarea",
          labelPosition: "top",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
          value: "",
        },
        {
          label: "不合格情况描述",
          prop: "nonconforming",
          type: "textarea",
          labelPosition: "top",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
          value: "",
        },
        {
          label: "不合格品产生原因",
          prop: "nonReason",
          type: "textarea",
          labelPosition: "top",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
          value: "",
        },
        {
          label: "原因分析",
          prop: "causeAnalysis",
          type: "textarea",
          labelPosition: "top",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
          value: "",
        },
        {
          label: "纠正措施",
          prop: "rectify",
          type: "textarea",
          labelPosition: "top",
          gutter: 32,
          minRows: 3,
          maxRows: 5,
          span: 24,
          value: "",
        },
        {
          label: "附件",
          prop: "fileNames",
          minWidth: 300,
          editDisplay:false,
          addDisplay:false,
          formslot:true,
          viewDisplay:true,
          span:24
        }
      ],
    },
  ]
})

//文件下载
const downloadFileHandler=async (row)=> {
  downloadFile(row.id, row.name, "/mes");
}
</script>

<style lang="scss" scoped>

</style>
